package com.woniu.ly.productassembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.ly.model.model.Product;
import com.woniu.ly.model.model.ProductImg;
import com.woniu.ly.model.model.ProductScheduing;

import com.woniu.ly.productassembly.dao.ProductImgMapper;
import com.woniu.ly.productassembly.dao.ProductMapper;
import com.woniu.ly.productassembly.dao.ProductScheduingMapper;
import com.woniu.ly.productassembly.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ProductScheduingMapper productScheduingMapper;

    @Autowired
    private ProductImgMapper productImgMapper;

    //添加产品基本信息
    public int makeProduct(Product product) {
        productMapper.insert(product);
        return product.getProductId();
    }

    //添加产品日程
    public void addProductScheduing(ProductScheduing productScheduing) {
        productScheduingMapper.insert(productScheduing);
    }

    //添加产品图片
    public void addProductImg(ProductImg productImg) {
        productImgMapper.insert(productImg);
    }

    //根据产品id查询产品
    public Product getProductById(int productId) {
        return productMapper.selectById(productId);
    }

    //查询所有产品
    public List<Product> getAllProducts() {
        return productMapper.getAllProducts();
    }

    //根据产品id查询产品日程安排
    public List<ProductScheduing> getProductScheduingById(int productId) {
        QueryWrapper<ProductScheduing> wrapper = new QueryWrapper<>();
        wrapper.eq("product_id",productId);
        return productScheduingMapper.selectList(wrapper);
    }

    //根据产品id查询产品图片
    public List<ProductImg> getProductImgById(int productId) {
        QueryWrapper<ProductImg> wrapper = new QueryWrapper<>();
        wrapper.eq("product_id",productId);
        return productImgMapper.selectList(wrapper);
    }

    //根据产品id修改产品基本信息
    public void modifyProductById(Product product) {
        productMapper.updateById(product);
    }

    //修改产品行程
    public void modifyProductScheduingById(ProductScheduing productScheduing) {
        productScheduingMapper.updateById(productScheduing);
    }


}
